<?php
/**
 * 项目模型
 * @author qianxun
 *
 */
class projectModel extends MY_Model{
    function projectModel(){
        parent::MY_Model();
        $this->table = 'Project';
    }
    /**
     * 包装数据(non-PHPdoc)
     * @see MY_Model::packing()
     */
    function packing($list = array()){
        //时段配置列表
        $this->load->model('timeUnitModel');
        $timeUnitList = $this->timeUnitModel->getCacheData('timeUnitList');
        //项目类型
        $this->load->model('proTypeModel');
        $proTypeList = $this->proTypeModel->getCacheData('proTypeAllList');
        
        $proStatus = $this->config->item('proStatus');
        $nowTime = time();
        foreach ($list as $k => $v){
            //发布状态标识
            if ($v['status'] == 0){//待发布
                $v['proStatus'] = 0;
            }else{//已发布
                $v['proStatus'] = $v['endTime'] <= $nowTime ? 2 : 1;
            }
            //状态文字
            $v['proStatusName'] = isset($proStatus[$v['proStatus']]) ? $proStatus[$v['proStatus']] : '';
            $v['storeStatusCount'] = unserialize($v['storeStatusCount']);
            //时段名称
            $v['timeUnitStr'] = isset($timeUnitList[$v['year']][$v['timeUnit']]) ? $timeUnitList[$v['year']][$v['timeUnit']] : '';
            //项目类型名称
            $v['proTypeName'] = isset($proTypeList[$v['proTypeId']]) ? $proTypeList[$v['proTypeId']]['proTypeName'] : '';
            $list[$k] = $v;
        }
        return $list;
    }
    /**
     * 更新专营店各专题统计数
     * @param number $proId
     * @return boolean
     */
    function updateStoreStatusCount($proId){
        $this->load->model('storeProModel');
        $storeStatusCount = $this->storeProModel->countStoreAuditRs($proId);
        $data = array(
            'storeStatusCount' => serialize($storeStatusCount),
            'updateTime' => time(),
        );
        if ($this->edit(array('proId'=>$proId), $data)){
            return true;
        }else{
            return false;
        }
    }
}